<template>
	<view class="uni-common-pb uni-padding-wrap uni-common-mt">
		<view class="uni-hello-text">
			登陆状态：{{username}}
		</view>

		<!-- #ifndef H5 -->
		<button type="primary" @tap="doQRcode">扫描工单</button>
		<!-- #endif -->
		<!-- #ifdef H5 -->
		<button type="primary" @tap="inputWOcode">输入工单</button>
		<!-- #endif -->

		<button type="primary" @tap="searchTO">工单查询</button>

		<!-- #ifdef MP-WEIXIN -->
		<button type="primary" @tap="logout">退出登录</button>
		<!-- #endif -->

		<prompt :visible.sync="promptVisible" title="工单编号" placeholder="请输入工单" defaultValue="" mainColor="#e74a39" @confirm="clickPromptConfirm">
			<!-- 这里放入slot内容-->
			<text></text>
		</prompt>
	</view>
</template>

<script>
	import Prompt from '@/components/zz-prompt/index.vue'

	export default {
		components: {
			Prompt,
		},
		data() {
			return {
				username: '',
				promptVisible: false,
			};
		},
		// /相应右上角的功能按钮/
		onNavigationBarButtonTap(e) {
			this.logout();
		},
		onLoad(e) {
			//获取上次登录的账号
			uni.getStorage({
				key: 'username',
				success: (res) => {
					this.username = res.data;
				},
				fail: () => {

				}
			});

		},
		methods: {
			doQRcode(e) {
				let _this = this;
				uni.scanCode({
					onlyFromCamera: true,
					success: function(res) {
						console.log(res.result);
						var workorder = res.result.split("/", 1);
						uni.navigateTo({
							url: '../wodetail/wodetail?ispb=0&workordernumber=' + workorder,
						});
					}
				});
			},
			inputWOcode: function() {
				console.log(this.promptVisible);
				this.promptVisible = true;
			},
			clickPromptConfirm(val) {
				console.log(val)
				uni.navigateTo({
					url: '../wodetail/wodetail?ispb=0&workordernumber=' + val,
				});
			},
			searchTO(e) {
				uni.navigateTo({
					url: '../wosearch/wosearch',
				});
			},
			logout(e) {
				uni.setStorage({
					key: "password",
					data: "",
					success: (res) => {
						uni.reLaunch({
							url: '/pages/main/main'
						});
					},
					fail: () => {}
				});

			},
		}
	}
</script>

<style>
	button {
		margin-top: 30upx;
		margin-bottom: 30upx;
	}
</style>
